<?php
/*
 module:		红娘管理->红娘付费设置
 create_time:	2024-03-22 16:27:06
 author:    937658938@qq.com
 contact:
*/

namespace app\backend\controller;
use app\backend\service\ZhMatchmakerOrderService;
use app\backend\model\ZhMatchmakerOrder as ZhMatchmakerOrderModel;
use think\facade\Db;
class ZhMatchmakerOrder extends Admin
{
    /*首页数据列表*/
    function index()
    {
        if (!$this->request->isAjax()) {
            return view('index');
        } else {
            $limit           = $this->request->post('limit', 20, 'intval');
            $offset          = $this->request->post('offset', 0, 'intval');
            $where['o.order_sn']   = $this->request->param('order_sn', '', 'serach_in');
            $where['o.status'] = $this->request->param('status', '', 'serach_in');
            $page = floor($offset / $limit) + 1;
            $res  = ZhMatchmakerOrderService::indexList(formatWhere($where), $limit, $page);
            return json($res);
        }
    }

    /*修改*/
    function update()
    {
        if (!$this->request->isPost()) {
            $id = $this->request->get('id', '', 'serach_in');
            if (!$id) $this->error('参数错误');
            //查询数据
            $this->view->assign('info', checkData(ZhMatchmakerOrderModel::find($id)));
            return view('update');
        } else {
            $postField          = '*';
            $data      = $this->request->only(explode(',', $postField), 'post', null);
            $res = ZhMatchmakerOrderService::update($data);
            return json(['status' => '00', 'msg' => '修改成功','res'=>$res]);
        }
    }

    /**
     * @return \think\response\Json|\think\response\View
     * @author  lwx
     */
    function add()
    {
        if (!$this->request->isPost()) {
            $res = ZhMatchmakerOrderService::indexList(formatWhere([
                'status' => 1
            ]), 100, 1);
            $this->view->assign('level_rows', $res['rows']);
            return view('add');
        } else {
            $postField          = '*';
            $data               = $this->request->only(explode(',', $postField), 'post', null);
            $data['createtime'] = time();
            $res                = ZhMatchmakerOrderModel::create($data);
            return json(['status' => '00', 'msg' => '添加成功','req'=>$data]);
        }
    }

    /*删除*/
    function delete()
    {
        $idx = $this->request->post('id', '', 'serach_in');
        if (!$idx) $this->error('参数错误');
        try {
            ZhMatchmakerOrderModel::destroy(['id' => explode(',', $idx)], true);
        } catch (\Exception $e) {
            abort(config('my.error_log_code'), $e->getMessage());
        }
        return json(['status' => '00', 'msg' => '操作成功']);
    }

    /*查看详情*/
    function view(){
        $id = $this->request->get('id','','serach_in');
        if(!$id) $this->error('参数错误');
        $sql = 'select  o.id,o.m_id,o.a_id,o.price,o.status,o.order_sn,o.price,o.createtime,gc_zh_authentication.real_name,gc_zh_matchmaker.name 
                from gc_zh_matchmaker_order  as o  
                left join gc_zh_matchmaker  on o.m_id=gc_zh_matchmaker.matchmaker_id
                 left join  gc_zh_authentication on o.a_id=gc_zh_authentication.authentication_id
                where o.id = '.$id.' limit 1';
        $info = Db::connect('mysql')->query($sql);
        $this->view->assign('info',current($info));
        return view('view');
    }

}

?>